function getLoginUserid() {
    var loginUserid = "";
    $.ajax({
        url:"/system/getLoginUserInfo",
        type:"GET",
        async: false,
        success : function(result) {
            if(result){
                loginUserid = result.userid;
            }else{
                window.location.replace("/templates/login.html");
            }
        }
    });
    return loginUserid;
}

function getDatetime() {

    var timezone = 8;
    var offset_GMT = new Date().getTimezoneOffset();
    var nowDate = new Date().getTime();

    var today = new Date(nowDate + offset_GMT * 60 * 1000 + timezone * 60 * 60 * 1000);
    var date = today.getFullYear() + "-" + twoDigits(today.getMonth() + 1) + "-" + twoDigits(today.getDate());
    var time = twoDigits(today.getHours()) + ":" + twoDigits(today.getMinutes()) + ":" + twoDigits(today.getSeconds());
    $(".Time").html('当前时间：' + date + '  ' + time);
}

function twoDigits(val) {
    if (val < 10) return "0" + val;
    return val;
}



///////////////////////////////////////////

///////////////////////////////////////////


function initType(form) {
    var type = $('#fktypeid');
    if(type.children().length == 0){
        $.ajax({
            url:"/restful/find",
            type:"POST",
            data:JSON.stringify({"firstTable":"types"}),
            contentType: "application/json;charset=utf-8",
            dataType : "json",
            async:false,
            success : function(result) {
                var data = result.data;
                var count = result.count;
                type.append('<option value="">全部商品类别</option>');
                for(var i = 0 ; i < count ; i ++){
                    type.append("<option value='" + data[i].typeid + "'>" + data[i].typename + "</option>");
                }
                form.render("select");
            },
            error:function(msg){
                layer.alert(msg);
                type.append("<option value=''>加载错误</option>");
            }
        });
    }
}

function toDetail(goodsid) {
    localStorage.goodsid = goodsid;
    window.location.replace("/templates/front/goodsDetail.html");
}

function initState(form) {
    var state = $('#fkstateid');
    if(state.children().length == 0){
        $.ajax({
            url:"/restful/find",
            type:"POST",
            data:JSON.stringify({"firstTable":"states"}),
            contentType: "application/json;charset=utf-8",
            dataType : "json",
            async:false,
            success : function(result) {
                var data = result.data;
                var count = result.count;
                state.append('<option value="">全部订单状态</option>');
                for(var i = 0 ; i < count ; i ++){
                    state.append("<option value='" + data[i].stateid + "'>" + data[i].statename + "</option>");
                }
                form.render("select");
            },
            error:function(msg){
                layer.alert(msg);
                $('#fkstateid').append("<option value=''>加载错误</option>");
            }
        });
    }
}